package com.ssm.dto;

public class CommonResult<T> {

    private Integer code;

    private String message;

    private T data;

    public static <T> CommonResult<T> success(T data) {
        CommonResult<T> result = new CommonResult<T>();
        result.setCode(1);
        result.setMessage("this is a success message");
        result.setData(data);
        return result;
    }

    public static <T> CommonResult<T> error(T data, Integer code, String message) {
        CommonResult<T> result = new CommonResult<T>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static CommonResult<Void> error(Integer code, String message) {
        return error(null, code, message);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
